<?php
header("content-type:text/html;charset:utf-8");
$arr = $_FILES['file'];
if($arr != ''){
	$msg = [];
	if($arr['error'] == 0){
		$extarr = array(".txt", ".jpg", ".png");
		$ext = substr($arr['name'], strrpos($arr['name'], "."));
		if(in_array($ext, $extarr)){
			if($arr['size'] < 200000){
				$dir = "./upfile/";
				if(!file_exists($dir)){
					mkdir($dir);
				}
				$filename = date("Y-m-d H_i_s")." _ ".mt_rand(100000, 999999).$ext;
				$path = $dir . $filename;
				$re = move_uploaded_file($arr['tmp_name'], $path);
				if($re){
					$msg['msg'] = "文件上传成功！";
					$msg['path'] = $path;
				}
			}else{
				$msg['msg'] = "文件过大！";
			};
		}else{
			$msg['msg'] = "不允许上传的文件格式";
		};
	}else{
		$msg['msg'] = "文件上传错误！";
	};
	
	// var_dump($msg);
	echo json_encode($msg);
}
?>